﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using WorkSummary.Bussiness.Bll;
using WorkSummary.Bussiness.Model;
using WorkSummary.Common;

namespace WorkSummaryReoprter.ashx
{
    /// <summary>
    /// Report 的摘要说明
    /// </summary>
    public class Report : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            var action = context.Request["action"];
            var json = context.Request["json"];
            var sdate = context.Request["startDate"];
            var edate = context.Request["endDate"];
            switch (action)
            {
                case "GetAllReportByUserID":
                    context.Response.Write(JSONhelper.ToJson(BReport.Instance.GetAllReportByUser(sdate, edate)));
                    break;
                case "GetAllReport":
                    context.Response.Write(JSONhelper.ToJson(BReport.Instance.GetAllReport(sdate, edate)));
                    break;
                case "AddReport":
                    MReport mReport1 = JSONhelper.ConvertToObject<MReport>(json);
                    context.Response.Write(JSONhelper.ToJson(BReport.Instance.AddReport(mReport1)));
                    break;
                case "DelReport":
                    var IDs = context.Request["IDs"];
                    context.Response.Write(JSONhelper.ToJson(BReport.Instance.DelReport(IDs)));
                    break;
                case "ModifyReport":
                    MReport mReport2 = JSONhelper.ConvertToObject<MReport>(json);
                    context.Response.Write(JSONhelper.ToJson(BReport.Instance.ModifyReport(mReport2)));
                    break;
                default:
                    context.Response.Write(JSONhelper.ToJson(new { code = -1, msg = "no action matched！" }));
                    break;
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}